package com.example.featuresdk.model

import com.example.featuresdk.R
import java.text.SimpleDateFormat
import java.util.*

data class Topic (val key :String, val title :String, val icon: Int, val summary :String = "",
                  val timestampText: String){

    companion object{
        val topics : MutableList<Topic> = mutableListOf()

        private  val topicIcons: MutableMap<String,Int> = mutableMapOf()

        init {
            topicIcons["apache"] = R.drawable.ic_apache
            topicIcons["azure"] = R.drawable.ic_azure
            topicIcons["bigquery"] = R.drawable.ic_bigquery
            topicIcons["cassandra"] = R.drawable.ic_cassandra
            topicIcons["clickhouse"] = R.drawable.ic_clickhouse
            topicIcons["cockroachdb"] = R.drawable.ic_cockroachdb
            topicIcons["couchbase"] = R.drawable.ic_couchbase
            topicIcons["eclipse"] = R.drawable.ic_eclipse
            topicIcons["exasol"] = R.drawable.ic_exasol
            topicIcons["firebird"] = R.drawable.ic_firebird
            topicIcons["greenplum"] = R.drawable.ic_greenplum
            topicIcons["hana"] = R.drawable.ic_hana
            topicIcons["hibernate"] = R.drawable.ic_hibernate
            topicIcons["hive"] = R.drawable.ic_hive
            topicIcons["hsqldb"] = R.drawable.ic_hsqldb
            topicIcons["informix"] = R.drawable.ic_informix
            topicIcons["mariadb"] = R.drawable.ic_mariadb
            topicIcons["microsoft"] = R.drawable.ic_microsoft
            topicIcons["mongodb"] = R.drawable.ic_mongodb
            topicIcons["mysql"] = R.drawable.ic_mysql
            topicIcons["postgresql"] = R.drawable.ic_postgresql
            topicIcons["redshift"] = R.drawable.ic_redshift
            topicIcons["snowflake"] = R.drawable.ic_snowflake
            topicIcons["spark"] = R.drawable.ic_spark
            topicIcons["sqlite"] = R.drawable.ic_sqlite
            topicIcons["teradata"] = R.drawable.ic_teradata
            topicIcons["vertica"] = R.drawable.ic_vertica

            var hours = 5
            val calendar = Calendar.getInstance()
            val today = Date(System.currentTimeMillis())
            val dateFormat = SimpleDateFormat("MMM dd")
            val timeFormat = SimpleDateFormat("HH:mm")
            topicIcons.forEach { it ->

                hours -= 2
                calendar.add(Calendar.HOUR,hours)
                val time = calendar.time

                val fmtTime = if(time.before(today)){

                    dateFormat.format(time)
                }else{
                    timeFormat.format(time)
                }
//                Log.i("***************Date/Time***********","time=$time   today=$today    fmtTime=$fmtTime")

                topics.add(Topic(it.key,it.key.capitalize(Locale.US),it.value, it.key,fmtTime))
            }
        }
    }
}